package com.spring.sunflower.conversation;

import android.content.Context;
import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.SPUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.opensource.svgaplayer.SVGAImageView;
import com.opensource.svgaplayer.SVGAParser;
import com.opensource.svgaplayer.SVGAVideoEntity;
import com.spring.sunflower.bean.ChatPeopleBean;
import com.spring.sunflower.bean.CustomMessageBean;
import com.spring.sunflower.bean.InsertTimeBean;
import com.spring.sunflower.bean.MessageCustomEntity;
import com.spring.sunflower.bean.OfflineMessageBean;
import com.spring.sunflower.bean.OfflineMessageContainerBean;
import com.spring.sunflower.constant.Constant;
import com.spring.sunflower.event.BaseChatEvent;
import com.spring.sunflower.event.GiftSendSuccessEvent;
import com.spring.sunflower.event.ImageSendSuccessEvent;
import com.spring.sunflower.event.VoiceSendSuccessEvent;
import com.spring.sunflower.util.LogUtils;
import com.tencent.imsdk.v2.V2TIMConversation;
import com.tencent.imsdk.v2.V2TIMCustomElem;
import com.tencent.imsdk.v2.V2TIMManager;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.imsdk.v2.V2TIMMessageManager;
import com.tencent.imsdk.v2.V2TIMOfflinePushInfo;
import com.tencent.imsdk.v2.V2TIMSDKConfig;
import com.tencent.imsdk.v2.V2TIMSDKListener;
import com.tencent.imsdk.v2.V2TIMSendCallback;
import com.tencent.imsdk.v2.V2TIMUserFullInfo;
import com.tencent.imsdk.v2.V2TIMValueCallback;

import org.json.JSONException;
import org.json.JSONObject;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Kevin on 2021/7/12<br/>
 * <p>
 * Describe:<br/>
 */
public class ConversationManager {
    private static String mOtherShowName;
    private static String mOtherFaceUrl;
    public static String mOtherUserID;
    private static String mSelfUserID;
    private static String mSelfAvatar;
    private static String mSelfNickname;
    private static String TAG = "ConversationManager.java";

    public static CustomMessageBean processV2TIMMessage(V2TIMMessage message) {
        CustomMessageBean bean = null;
        V2TIMCustomElem customElem = message.getCustomElem();
        if (customElem == null) return null;
        String data = new String(customElem.getData());
        try {
            JSONObject jsonObject = new JSONObject(data);
            JSONObject object = jsonObject.getJSONObject("data");
            if (object.has("body")) {
                String type = object.getString("type");
                switch (type) {
                    case "4":


                        break;
                    case "5":
                        break;
                }
                return null;
            } else {
                bean = new Gson().fromJson(data, (new TypeToken<CustomMessageBean>() {
                }).getType());
            }
        } catch (Exception e) {

        }
        return bean;
    }

    public static CustomMessageBean processV2TIMMessage(V2TIMMessage message, CustomMessageBean.UserBean userBean) {
        CustomMessageBean bean = null;
        V2TIMCustomElem customElem = message.getCustomElem();
        if (customElem == null) return null;
        String data = new String(customElem.getData());
        try {
            JSONObject jsonObject = new JSONObject(data);
            JSONObject object = jsonObject.getJSONObject("data");
            if (object.has("body")) {
                String type = object.getString("type");
                switch (type) {
                    case "4":
                        String sender = object.getString("sender");
                        String photo = object.getString("photo");
                        String isVip = object.getString("isVip");
                        String nickname = object.getString("nickname");
                        String gender = object.getString("sex");
                        bean = new CustomMessageBean();
                        bean.data.fromUser.memberId = sender;
                        bean.data.fromUser.nickname = nickname;
                        bean.data.fromUser.photo = photo;
                        bean.data.toUser.memberId = userBean.memberId;
                        bean.data.toUser.nickname = userBean.nickname;
                        bean.data.toUser.photo = userBean.photo;
                        bean.data.msgType = Constant.CUSTOM_MESSAGE_VIDEO_CALL;
                        break;
                }
                return bean;
            } else {
                bean = new Gson().fromJson(data, (new TypeToken<CustomMessageBean>() {
                }).getType());
            }
        } catch (Exception e) {

        }
        return bean;
    }

    private static CustomMessageBean processVideoCallMessage(JSONObject object) {
        CustomMessageBean bean = null;
        try {
            String sender = object.getString("sender");
            String photo = object.getString("photo");
            String isVip = object.getString("isVip");
            String nickname = object.getString("nickname");
            String gender = object.getString("sex");
            bean = new CustomMessageBean();
            bean.data.fromUser.memberId = sender;
            bean.data.fromUser.nickname = nickname;
            bean.data.fromUser.photo = photo;
//            bean.data.toUser
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return bean;
    }

    public static String getField(String key, String defaultValue) {
        return SPUtils.getInstance().getString(key, defaultValue);
    }

    public static void saveField(String key, String value) {
        SPUtils.getInstance().put(key, value);
    }

    private static CustomMessageBean getCustomMessageBean() {
        mSelfUserID = getField(Constant.KEY_USERID, "");
        mSelfAvatar = getField(Constant.KEY_PHOTO, "");
        mSelfNickname = getField(Constant.KEY_NICKNAME, "");
        mOtherUserID = getField(Constant.KEY_USERID_CHATTER, "");
        mOtherFaceUrl = getField(Constant.KEY_AVATAR_CHATTER, "");
        mOtherShowName = getField(Constant.KEY_NICKNAME_CHATTER, "");
        CustomMessageBean customMessageBean = new CustomMessageBean();
        CustomMessageBean.DataBean dataBean = new CustomMessageBean.DataBean();
        CustomMessageBean.DataBean.UserBean userBeanOther = new CustomMessageBean.DataBean.UserBean();
        userBeanOther.memberId = mOtherUserID;
        userBeanOther.nickname = mOtherShowName;
        userBeanOther.photo = mOtherFaceUrl;
        CustomMessageBean.DataBean.UserBean userBeanSelf = new CustomMessageBean.DataBean.UserBean();
        userBeanSelf.memberId = mSelfUserID;
        userBeanSelf.nickname = mSelfNickname;
        userBeanSelf.photo = mSelfAvatar;
        userBeanSelf.selfSend = "1";//自己发送
        dataBean.fromUser = userBeanSelf;
        dataBean.toUser = userBeanOther;
        customMessageBean.data = dataBean;
        return customMessageBean;
    }
    /**
     * 视频通话未接通的情况下插入到拨打方本地
     *
     * @param content
     * @param callback
     */
    public static void insertLocalMessage(String content, V2TIMValueCallback<V2TIMMessage> callback) {
        //根据类型添加发送内容
        mSelfUserID = getField(Constant.KEY_USERID, "");
        mOtherUserID = getField(Constant.KEY_USERID_CHATTER, "");
        CustomMessageBean customMessageBean = getCustomMessageBean();
        customMessageBean.data.msgType = Constant.CUSTOM_MESSAGE_TEXT;
        customMessageBean.data.time = System.currentTimeMillis();
        customMessageBean.data.content = content;
        String json = new Gson().toJson(customMessageBean, (new TypeToken<CustomMessageBean>() {
        }).getType());
        V2TIMMessageManager messageManager = V2TIMManager.getMessageManager();
        V2TIMMessage customMessage = messageManager.createCustomMessage(json.getBytes());
        messageManager.insertC2CMessageToLocalStorage(customMessage, mOtherUserID, mSelfUserID, callback);
    }

    /**
     * 插入时间
     *
     * @param msgType
     * @param isSend
     * @param callback
     */
    public static void insertLocalMessage(String msgType, boolean isSend, V2TIMValueCallback<V2TIMMessage> callback) {
        //根据类型添加发送内容
        mSelfUserID = getField(Constant.KEY_USERID, "");
        mOtherUserID = getField(Constant.KEY_USERID_CHATTER, "");

        String storage = getField(Constant.CHATTED_TIME_STORAGE, "");
        if (!TextUtils.isEmpty(storage)) {
            Gson gson = new Gson();
            InsertTimeBean insertTimeBean = gson.fromJson(storage, InsertTimeBean.class);
            List<InsertTimeBean.DataBean> data = insertTimeBean.getData();
            List<String> userIDList = new ArrayList<>();
            for (InsertTimeBean.DataBean d : data) {
                userIDList.add(d.getUserID());
            }
            if (userIDList.contains(mOtherUserID)) {//包含就更新
                for (int i = 0; i < data.size(); i++) {
                    InsertTimeBean.DataBean dataBean = data.get(i);
                    if (mOtherUserID.equals(dataBean.getUserID())) {
                        dataBean.setLastChatTime(System.currentTimeMillis());
                        data.set(i, dataBean);//更新时间然后存储
                        insertTimeBean.setData(data);
                        String json = new Gson().toJson(insertTimeBean);
                        saveField(Constant.CHATTED_TIME_STORAGE, json);
                        break;
                    }
                }
            } else {//不包含就添加
                InsertTimeBean.DataBean dataBean = new InsertTimeBean.DataBean();
                dataBean.setUserID(mOtherUserID);
                dataBean.setLastChatTime(System.currentTimeMillis());
                data.add(dataBean);
                insertTimeBean.setData(data);
                String json = new Gson().toJson(insertTimeBean);
                saveField(Constant.CHATTED_TIME_STORAGE, json);
            }
        } else {//没有存储过就重新创建
            InsertTimeBean insertTimeBean = new InsertTimeBean();
            List<InsertTimeBean.DataBean> data = new ArrayList<>();
            InsertTimeBean.DataBean dataBean = new InsertTimeBean.DataBean();
            dataBean.setUserID(mOtherUserID);
            dataBean.setLastChatTime(System.currentTimeMillis());
            data.add(dataBean);
            insertTimeBean.setData(data);
            String json = new Gson().toJson(insertTimeBean);
            saveField(Constant.CHATTED_TIME_STORAGE, json);
        }


        CustomMessageBean customMessageBean = getCustomMessageBean();
        customMessageBean.data.msgType = msgType;

//            GiftSendSuccessEvent e = (GiftSendSuccessEvent) event.getEvent();
//            CustomMessageBean.DataBean.GiftBean giftBean = new CustomMessageBean.DataBean.GiftBean();
//            giftBean.name = e.getGiftName();
//            giftBean.effects = e.getGiftEffect();
//            giftBean.imagePath = e.getGiftPath();
//            giftBean.number = e.getGiftNum();
//            customMessageBean.data.setGift(giftBean);
//        }
//        if (msgType == Constant.CUSTOM_MESSAGE_SOUND) {
//            VoiceSendSuccessEvent e = (VoiceSendSuccessEvent) event.getEvent();
//            CustomMessageBean.DataBean.AudioBean audioBean = new CustomMessageBean.DataBean.AudioBean();
//            audioBean.duration = Integer.valueOf(e.getDuration());
//            audioBean.url = e.getAudioUrl();
//            customMessageBean.data.setAudio(audioBean);
//        }
//        if (msgType == Constant.CUSTOM_MESSAGE_PICTURE) {
//            ImageSendSuccessEvent e = (ImageSendSuccessEvent) event.getEvent();
//            CustomMessageBean.DataBean.PictureBean pictureBean = new CustomMessageBean.DataBean.PictureBean();
//            pictureBean.width = e.getWidth();
//            pictureBean.height = e.getHeight();
//            pictureBean.url = e.getImgUrl();
//            customMessageBean.data.setPicture(pictureBean);
//        }
        customMessageBean.data.time = System.currentTimeMillis();
        customMessageBean.data.content = "系统提示";
        String json = new Gson().toJson(customMessageBean, (new TypeToken<CustomMessageBean>() {
        }).getType());
        V2TIMMessageManager messageManager = V2TIMManager.getMessageManager();
        V2TIMMessage customMessage = messageManager.createCustomMessage(json.getBytes());
        messageManager.insertC2CMessageToLocalStorage(customMessage, mOtherUserID, isSend ? mSelfUserID : mOtherUserID, callback);
    }

    public static void sendMessage(String data, String msgType, BaseChatEvent event, V2TIMSendCallback<V2TIMMessage> callback) {
        //根据类型添加发送内容
        CustomMessageBean customMessageBean = getCustomMessageBean();
        customMessageBean.data.msgType = msgType;
        if (msgType == Constant.CUSTOM_MESSAGE_GIFT) {
            GiftSendSuccessEvent e = (GiftSendSuccessEvent) event.getEvent();
            CustomMessageBean.DataBean.GiftBean giftBean = new CustomMessageBean.DataBean.GiftBean();
            giftBean.name = e.getGiftName();
            giftBean.effects = e.getGiftEffect();
            giftBean.imagePath = e.getGiftPath();
            giftBean.number = e.getGiftNum();
            customMessageBean.data.setGift(giftBean);
        }
        if (msgType == Constant.CUSTOM_MESSAGE_SOUND) {
            VoiceSendSuccessEvent e = (VoiceSendSuccessEvent) event.getEvent();
            CustomMessageBean.DataBean.AudioBean audioBean = new CustomMessageBean.DataBean.AudioBean();
            audioBean.duration = Integer.valueOf(e.getDuration());
            audioBean.url = e.getAudioUrl();
            customMessageBean.data.setAudio(audioBean);
        }
        if (msgType == Constant.CUSTOM_MESSAGE_PICTURE) {
            ImageSendSuccessEvent e = (ImageSendSuccessEvent) event.getEvent();
            CustomMessageBean.DataBean.PictureBean pictureBean = new CustomMessageBean.DataBean.PictureBean();
            pictureBean.width = e.getWidth();
            pictureBean.height = e.getHeight();
            pictureBean.url = e.getImgUrl();
            customMessageBean.data.setPicture(pictureBean);
        }
        customMessageBean.data.time = System.currentTimeMillis();
        customMessageBean.data.content = data;
        String json = new Gson().toJson(customMessageBean, (new TypeToken<CustomMessageBean>() {
        }).getType());
        V2TIMMessageManager messageManager = V2TIMManager.getMessageManager();
        V2TIMMessage customMessage = messageManager.createCustomMessage(json.getBytes());

        OfflineMessageContainerBean containerBean = new OfflineMessageContainerBean();
        OfflineMessageBean entity = new OfflineMessageBean();
        entity.content = data;
        entity.sender = mSelfUserID;
        entity.nickname = mSelfNickname;
        entity.faceUrl = mSelfAvatar;
        containerBean.entity = entity;
        V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();
        v2TIMOfflinePushInfo.setExt(new Gson().toJson(containerBean).getBytes());
        messageManager.sendMessage(customMessage, mOtherUserID, null, V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, v2TIMOfflinePushInfo, callback);
    }

    public static MessageCustomEntity customMessageBean2MessageCustomEntity(CustomMessageBean customMessageBean, V2TIMMessage msg) {
        mSelfAvatar = getField(Constant.KEY_PHOTO, "");
        mOtherFaceUrl = getField(Constant.KEY_AVATAR_CHATTER, "");
        CustomMessageBean.DataBean data = customMessageBean.data;
        if (data == null) return null;
        String msgType = data.msgType;
        MessageCustomEntity messageCustomEntity = new MessageCustomEntity();
        switch (msgType) {
            case Constant.CUSTOM_MESSAGE_TEXT:
                messageCustomEntity.setItemType(MessageCustomEntity.MSG_TYPE_TEXT);
                break;
            case Constant.CUSTOM_MESSAGE_GIFT:
                messageCustomEntity.setItemType(MessageCustomEntity.MSG_TYPE_CUSTOM_GIFT);
                if (data.gift != null) {
                    if (data.gift.imagePath != null) {
                        messageCustomEntity.setGiftImagePath(data.gift.imagePath);
                    }
                    if (data.gift.effects != null) {
                        messageCustomEntity.setGiftEffects(data.gift.effects);
                    }
                    if (data.gift.name != null) {
                        messageCustomEntity.setGiftName(data.gift.name);
                    }
                    if (data.gift.number != null) {
                        messageCustomEntity.setGiftNumber(data.gift.number);
                    }
                }
                break;
            case Constant.CUSTOM_MESSAGE_SOUND:
                messageCustomEntity.setItemType(MessageCustomEntity.MSG_TYPE_AUDIO);
                messageCustomEntity.setAudioUrl(data.audio.url);
                messageCustomEntity.setAudioDuration(data.audio.duration);
                break;
            case Constant.CUSTOM_MESSAGE_PICTURE:
                messageCustomEntity.setItemType(MessageCustomEntity.MSG_TYPE_IMAGE);
                if (data.picture != null) {
                    messageCustomEntity.setPicUrl(data.picture.url);
                    messageCustomEntity.setPicWidth(data.picture.width);
                    messageCustomEntity.setPicHeight(data.picture.height);
                }
                break;
            case Constant.CUSTOM_MESSAGE_SYSTEM:
                break;
            case Constant.CUSTOM_MESSAGE_VIDEO_CALL:
                messageCustomEntity.setItemType(MessageCustomEntity.MSG_TYPE_CUSTOM);
                break;
            case Constant.CUSTOM_MESSAGE_LOCAL_TIME:
                messageCustomEntity.setItemType(MessageCustomEntity.MSG_TYPE_TIME);
                break;
        }
        messageCustomEntity.setContent(data.content);

        String fromUserPhoto = msg.isSelf() ? mSelfAvatar : mOtherFaceUrl;
        String fromUserNickname = data.fromUser.getNickname();
        String fromUserMemberId = data.fromUser.getMemberId();
        String toUserPhoto = data.toUser.getPhoto();
        String toUserMemberId = data.toUser.getMemberId();
        String toUserNickname = data.toUser.getNickname();
        messageCustomEntity.setFromUserMemberId(fromUserMemberId);
        messageCustomEntity.setFromUserNickname(fromUserNickname);
        messageCustomEntity.setFromUserPhoto(fromUserPhoto);
        messageCustomEntity.setToUserMemberId(toUserMemberId);
        messageCustomEntity.setToUserNickname(toUserNickname);
        messageCustomEntity.setToUserPhoto(toUserPhoto);
        messageCustomEntity.setMsgID(msg.getMsgID());
        messageCustomEntity.setRandom(msg.getRandom());
        messageCustomEntity.setSelf(msg.isSelf());
        messageCustomEntity.setStatus(msg.getStatus());
        messageCustomEntity.setTimestamp(msg.getTimestamp());
        messageCustomEntity.setSeq(msg.getSeq());
        return messageCustomEntity;
    }

    public static void playSVGA(Context context, SVGAImageView svgaImageView, String source) {
        SVGAParser svgaParser = new SVGAParser(context);
        SVGAParser.ParseCompletion parseCompletion = new SVGAParser.ParseCompletion() {

            @Override
            public void onError() {

            }

            @Override
            public void onComplete(@NonNull SVGAVideoEntity svgaVideoEntity) {
                svgaVideoEntity.setAntiAlias(true);
                svgaImageView.setVideoItem(svgaVideoEntity);
                svgaImageView.startAnimation();

            }
        };
        if (source.startsWith("http://") || source.startsWith("https://")) {
            try {
                svgaParser.decodeFromURL(new URL(source), parseCompletion);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void initV2TIMSDK(Context context) {
        String environment = getField(Constant.KEY_ENVIRONMENT, Constant.ENVIRONMENT_PRODUCT);
        V2TIMSDKConfig config = new V2TIMSDKConfig();
        config.setLogLevel(V2TIMSDKConfig.V2TIM_LOG_DEBUG);
        int sig = Constant.TRTC_APPID_PRODUCT;
        if (environment.equals(Constant.ENVIRONMENT_PRODUCT)) {
            sig = Constant.TRTC_APPID_PRODUCT;
        } else {
            sig = Constant.TRTC_APPID_TEST;
        }
        LogUtils.INSTANCE.logD("MainActivity", "environment=" + environment + ",sig=" + sig);
        V2TIMManager.getInstance().initSDK(context, sig, config, new V2TIMSDKListener() {
            @Override
            public void onConnecting() {
                super.onConnecting();
            }

            @Override
            public void onConnectSuccess() {
                super.onConnectSuccess();

                LogUtils.INSTANCE.logD(TAG, "success");
            }

            @Override
            public void onConnectFailed(int code, String error) {
                super.onConnectFailed(code, error);
                LogUtils.INSTANCE.logD(TAG, "code=" + code + ",error=" + error);
            }

            @Override
            public void onKickedOffline() {
                super.onKickedOffline();
                LogUtils.INSTANCE.logD(TAG, "onKickedOffline");
            }

            @Override
            public void onUserSigExpired() {
                super.onUserSigExpired();
                LogUtils.INSTANCE.logD(TAG, "onUserSigExpired");
            }

            @Override
            public void onSelfInfoUpdated(V2TIMUserFullInfo info) {
                super.onSelfInfoUpdated(info);
                LogUtils.INSTANCE.logD(TAG, "onSelfInfoUpdated");
            }
        });
    }

    /**
     * 判断是否应该在聊天列表里面插入时间
     *
     * @return true为插入 false为不插入
     */
    public static boolean shouldInsertTime() {
        mOtherUserID = getField(Constant.KEY_USERID_CHATTER, "");
        String storage = getField(Constant.CHATTED_TIME_STORAGE, "");
        if (!TextUtils.isEmpty(storage)) {
            Gson gson = new Gson();
            InsertTimeBean insertTimeBean = gson.fromJson(storage, InsertTimeBean.class);
            List<InsertTimeBean.DataBean> data = insertTimeBean.getData();
            List<String> userIDList = new ArrayList<>();
            for (InsertTimeBean.DataBean d : data) {
                userIDList.add(d.getUserID());
            }
            if (userIDList.contains(mOtherUserID)) {
                //包含判断时间b
                for (int i = 0; i < data.size(); i++) {
                    InsertTimeBean.DataBean dataBean = data.get(i);
                    if (dataBean.getUserID().equals(mOtherUserID)) {
                        Long lastChatTime = dataBean.getLastChatTime();
                        long l1 = (System.currentTimeMillis() - lastChatTime) / (1000*60);
                        if (l1 >= 5) {
                            return true;
                        }
                    }
                }
            } else {
                return true;
            }
        } else {
            return true;
        }
        return false;
    }

    /**
     * 该条消息是不是陌生人消息
     *
     * @param hasChattedData 聊过天的数据
     * @param userID         会话人的userID
     * @return true是陌生人消息，false不是陌生人消息
     */
    public static boolean isStrangeMsg(List<ChatPeopleBean.DatasBean> hasChattedData, String userID) {
        for (int i = 0; i < hasChattedData.size(); i++) {
//            LogUtils.INSTANCE.logW("MessageFragment", "anchoridID=" + hasChattedData.get(i).getAnchorId() + ",userID=" + userID);
            String anchorId = hasChattedData.get(i).getToMemberId();
            if (anchorId != null) {
                if (anchorId.equals(userID)) {
                    return false;
                }
            }
        }
        return true;
    }

    /**
     * 获取当前userID在集合中的V2TIMConversation
     *
     * @param data   陌生人消息集合
     * @param userID
     * @return
     */
    public static V2TIMConversation getConversation(List<V2TIMConversation> data, String userID) {
        for (int i = 0; i < data.size(); i++) {
            if (data.get(i).getUserID().equals(userID)) {
                return data.get(i);
            }
        }
        return null;
    }

    public static String getLastMessage(V2TIMMessage lastMessage) {
        if (lastMessage == null) return "";
        CustomMessageBean bean = ConversationManager.processV2TIMMessage(lastMessage);
//        MessageCustomEntity messageCustomEntity = ConversationManager.customMessageBean2MessageCustomEntity(bean, lastMessage);
        LogUtils.INSTANCE.logI("MessageAdapter", "eleType=" + lastMessage.getElemType());
        if (bean == null) return "";
        CustomMessageBean.DataBean data = bean.data;
        String msg = "";
        LogUtils.INSTANCE.logI("MessageAdapter", "content=" + data.content);
        switch (data.msgType) {
            case Constant.CUSTOM_MESSAGE_TEXT:
                msg = data.content;
                break;
            case Constant.CUSTOM_MESSAGE_PICTURE:
                msg = "[图片]";
                break;
            case Constant.CUSTOM_MESSAGE_SOUND:
                msg = "[语音]";
                break;
            case Constant.CUSTOM_MESSAGE_VIDEO:
                msg = "[视频]";
                break;
            case Constant.CUSTOM_MESSAGE_FILE:
                msg = "[文件]";
                break;
            case Constant.CUSTOM_MESSAGE_LOCATION:
                msg = "[位置]";
                break;
            case Constant.CUSTOM_MESSAGE_GIFT:
                msg = "[礼物]";
                break;
            case Constant.CUSTOM_MESSAGE_LOCAL_TIME:
                msg = "[提示消息]";
                break;
            default:
                msg = "[不支持的消息类型]";
                break;
        }

        return msg;
    }
}
